package UDP;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Serve {
    public static void main(String args[]) throws Exception{

        System.out.println("服务端启动");
        //new 一个服务端
        DatagramSocket socket=new DatagramSocket(6666); //声明端口

        // new 一个接受数据的对象
        byte[] buffer=new byte[1024*64];//64kb
        DatagramPacket packet=new DatagramPacket(buffer,buffer.length);

        while (true) {


            // 接受客服端的数据
            socket.receive(packet);

            int len=packet.getLength();
            String rs = new String(buffer,0,len);
            System.out.println(rs);
            System.out.println(packet.getAddress());
        }

    }
}
